#pragma once
#include <string>
#include <Windows.h>

struct CacheEntry
{
	UINT keyLength;
	UINT bytecodeLength;
	const char * key;
	const void * bytecode;
};

class ShaderCache
{
private:
	std::string m_cacheRoot;
	void WriteCacheEntry(HANDLE hFile, const CacheEntry & entry);
	UINT CalculateCacheEntrySize(const CacheEntry & entry);
	bool ReadCacheEntry(HANDLE hFile, CacheEntry & entry, bool readBytecode);

	bool SearchForEntry(CacheEntry& entry, const TCHAR * fileName, const TCHAR * shaderFileName);
	void AddCacheEntry(const CacheEntry & entry, const TCHAR * fileName, const TCHAR * shaderFileName);

	void CreateCacheFileName(const std::string& shaderFileName, std::string& result);
public:
	ShaderCache(std::string& cacheRoot);
	virtual ~ShaderCache(void);

	bool SearchForEntry(CacheEntry& entry, const std::string& shaderFileName);
	void AddCacheEntry(const CacheEntry & entry, const std::string& shaderFileName);
};

